/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

/**
 * <p>Project: jse2204 - LocalTime1
 * <p>Powered by webrx On 2022-08-31 14:09:43
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class LocalTime1 {
    public static void main(String[] args) {
        LocalTime time = LocalTime.of(16,4,5);

        //格式化时 hh 12小时制  HH24小时
        DateTimeFormatter tt = DateTimeFormatter.ofPattern("HH:mm:ss");
        System.out.println(time.format(tt));
        System.out.println(time.plusHours(2).format(tt));

        System.out.println(time.minusMinutes(15));

        //LocalDateTime = LocalDate + LocalTime  相当于 时间戳 java.util.Date java.util.Calendar
        LocalDateTime n1 = LocalDateTime.now(ZoneId.of("+08:00"));
        System.out.println(n1);
        LocalDateTime n2 = LocalDateTime.now();
        System.out.println(n2);

        DateTimeFormatter ff = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(n2.format(ff));

        //获取时间戳
        //n2.toLocalTime()  LoalTime
        //n2.toLocalDate() LocalDate
        //获取秒数
        long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        //获取毫秒数(时间戳)
        long milliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        System.out.println(milliSecond);
        System.out.println(System.currentTimeMillis());

        System.out.printf("%tF %tT%n", LocalDate.now(),LocalTime.now());
        System.out.printf("%tF %<tT%n", LocalDateTime.now());

        //将LocalDateTime 转换为 java.util.Date
        Date dd1 = new Date(milliSecond);
        System.out.printf("%tF %<tT%n", dd1);

        //将Date转换为java.util.Date
        var da = new Date();
        var db = da.toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();



    }
}
